package com.hgc.ch01.base;

/**
 * Created by 01367627 on 2019/7/5.
 */
public class JoinThread {

    private static class Goddness extends Thread{

        private Thread goddnessBoyFriend;

        public Goddness(Thread goddnessBoyFriend) {
            this.goddnessBoyFriend = goddnessBoyFriend;
        }

        @Override
        public void run() {
            System.out.println("Goddness 开始排队打饭");
            try {
                goddnessBoyFriend.start();
                goddnessBoyFriend.join();
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Goddness 打饭完成");
        }
    }

    private static class GoddnessBoyFriend extends Thread{
        @Override
        public void run() {
            System.out.println("Goddness 男神开始排队打饭");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Goddness 男神打饭完成");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread.currentThread().setName("Lison");
        System.out.println("Lison 开始排队打饭");
        Thread gbf = new GoddnessBoyFriend();
        Thread goddness = new Goddness(gbf);
        goddness.start();
        goddness.join();
        Thread.sleep(2000);
        System.out.println("Lison 打饭完成");
    }

}
